import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * customize - API 个性化 Service
 * @date: 2019-7-8
 */
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { getCurrentOrganizationId, isTenantRoleLevel } from 'utils/utils';
var isSiteFlag = !isTenantRoleLevel();
var tenantId = getCurrentOrganizationId();
var pointPrefix = isSiteFlag ? "/v1/customize-points" : "/v1/".concat(tenantId, "/customize-points");
var rulePrefix = isSiteFlag ? "/v1/customize-rules" : "/v1/".concat(tenantId, "/customize-rules");
var rangePrefix = isSiteFlag ? "/v1/customize-ranges" : "/v1/".concat(tenantId, "/customize-ranges");
/**
 * 查询个性化切入点列表
 * @param {Object} params - 查询参数
 * @param {String} params.page - 页码
 * @param {String} params.size - 页数
 */

export function fetchPointList(_x) {
  return _fetchPointList.apply(this, arguments);
}
/**
 * 刷新服务
 * refreshPoint
 * @param {Object} params - 查询参数
 */

function _fetchPointList() {
  _fetchPointList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM).concat(pointPrefix), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchPointList.apply(this, arguments);
}

export function refreshPoint(_x2) {
  return _refreshPoint.apply(this, arguments);
}
/**
 * 删除
 * deletePoint
 * @param {Object} params - 查询参数
 */

function _refreshPoint() {
  _refreshPoint = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM).concat(pointPrefix, "/refresh"), {
              method: 'POST',
              query: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _refreshPoint.apply(this, arguments);
}

export function deletePoint(_x3) {
  return _deletePoint.apply(this, arguments);
}
/**
 * 查询个性化规则列表
 * @param {Object} params - 查询参数
 * @param {String} params.page - 页码
 * @param {String} params.size - 页数
 */

function _deletePoint() {
  _deletePoint = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM).concat(pointPrefix), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _deletePoint.apply(this, arguments);
}

export function fetchRuleList(_x4) {
  return _fetchRuleList.apply(this, arguments);
}
/**
 * 查询个性化规则明细
 * @param {Object} params - 查询参数
 */

function _fetchRuleList() {
  _fetchRuleList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM).concat(rulePrefix), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _fetchRuleList.apply(this, arguments);
}

export function fetchRuleDetail(_x5) {
  return _fetchRuleDetail.apply(this, arguments);
}
/**
 *  创建
 * createRule
 * @param {Object} params - 查询参数
 */

function _fetchRuleDetail() {
  _fetchRuleDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(CPAAS_PLATFORM).concat(rulePrefix, "/").concat(params.ruleId), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _fetchRuleDetail.apply(this, arguments);
}

export function createRule(_x6) {
  return _createRule.apply(this, arguments);
}
/**
 *  更新
 * updateRule
 * @param {Object} params - 查询参数
 */

function _createRule() {
  _createRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request("".concat(CPAAS_PLATFORM).concat(rulePrefix), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _createRule.apply(this, arguments);
}

export function updateRule(_x7) {
  return _updateRule.apply(this, arguments);
}
/**
 *  删除
 * deleteRule
 * @param {Object} params - 查询参数
 */

function _updateRule() {
  _updateRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            return _context7.abrupt("return", request("".concat(CPAAS_PLATFORM).concat(rulePrefix), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _updateRule.apply(this, arguments);
}

export function deleteRule(_x8) {
  return _deleteRule.apply(this, arguments);
}
/**
 * 查询个性化范围列表
 * fetchRangeList
 * @param {Object} params - 查询参数
 */

function _deleteRule() {
  _deleteRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(params) {
    return _regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            return _context8.abrupt("return", request("".concat(CPAAS_PLATFORM).concat(rulePrefix), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  }));
  return _deleteRule.apply(this, arguments);
}

export function fetchRangeList(_x9) {
  return _fetchRangeList.apply(this, arguments);
}
/**
 * fetchRangeDetail
 * 查询个性化范围明细
 * @param {Object} params - 查询参数
 */

function _fetchRangeList() {
  _fetchRangeList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(params) {
    return _regeneratorRuntime.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            return _context9.abrupt("return", request("".concat(CPAAS_PLATFORM).concat(rangePrefix), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9);
  }));
  return _fetchRangeList.apply(this, arguments);
}

export function fetchRangeDetail(_x10) {
  return _fetchRangeDetail.apply(this, arguments);
}
/**
 *  创建
 * createRange
 * @param {Object} params - 查询参数
 */

function _fetchRangeDetail() {
  _fetchRangeDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(params) {
    return _regeneratorRuntime.wrap(function _callee10$(_context10) {
      while (1) {
        switch (_context10.prev = _context10.next) {
          case 0:
            return _context10.abrupt("return", request("".concat(CPAAS_PLATFORM).concat(rangePrefix, "/").concat(params.rangeId), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context10.stop();
        }
      }
    }, _callee10);
  }));
  return _fetchRangeDetail.apply(this, arguments);
}

export function createRange(_x11) {
  return _createRange.apply(this, arguments);
}
/**
 *  更新
 * updateRange
 * @param {Object} params - 查询参数
 */

function _createRange() {
  _createRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(params) {
    return _regeneratorRuntime.wrap(function _callee11$(_context11) {
      while (1) {
        switch (_context11.prev = _context11.next) {
          case 0:
            return _context11.abrupt("return", request("".concat(CPAAS_PLATFORM).concat(rangePrefix), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context11.stop();
        }
      }
    }, _callee11);
  }));
  return _createRange.apply(this, arguments);
}

export function updateRange(_x12) {
  return _updateRange.apply(this, arguments);
}
/**
 *  删除
 * deleteRange
 * @param {Object} params - 查询参数
 */

function _updateRange() {
  _updateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(params) {
    return _regeneratorRuntime.wrap(function _callee12$(_context12) {
      while (1) {
        switch (_context12.prev = _context12.next) {
          case 0:
            return _context12.abrupt("return", request("".concat(CPAAS_PLATFORM).concat(rangePrefix), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context12.stop();
        }
      }
    }, _callee12);
  }));
  return _updateRange.apply(this, arguments);
}

export function deleteRange(_x13) {
  return _deleteRange.apply(this, arguments);
}
/**
 * 查询个性化范围-切入点
 * fetchPointListToRange
 * @param {Object} params - 查询参数
 */

function _deleteRange() {
  _deleteRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(params) {
    return _regeneratorRuntime.wrap(function _callee13$(_context13) {
      while (1) {
        switch (_context13.prev = _context13.next) {
          case 0:
            return _context13.abrupt("return", request("".concat(CPAAS_PLATFORM).concat(rangePrefix), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context13.stop();
        }
      }
    }, _callee13);
  }));
  return _deleteRange.apply(this, arguments);
}

export function fetchPointListToRange(_x14) {
  return _fetchPointListToRange.apply(this, arguments);
}
/**
 * 查询个性化范围-规则
 * fetchPointListToRule
 * @param {Object} params - 查询参数
 */

function _fetchPointListToRange() {
  _fetchPointListToRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(params) {
    return _regeneratorRuntime.wrap(function _callee14$(_context14) {
      while (1) {
        switch (_context14.prev = _context14.next) {
          case 0:
            return _context14.abrupt("return", request("".concat(CPAAS_PLATFORM).concat(rangePrefix, "/").concat(params.rangeId, "/points"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context14.stop();
        }
      }
    }, _callee14);
  }));
  return _fetchPointListToRange.apply(this, arguments);
}

export function fetchRuleListToRange(_x15) {
  return _fetchRuleListToRange.apply(this, arguments);
}
/**
 * 删除切入点
 *  deletePointToRange
 * @param {Object} params - 查询参数
 */

function _fetchRuleListToRange() {
  _fetchRuleListToRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(params) {
    return _regeneratorRuntime.wrap(function _callee15$(_context15) {
      while (1) {
        switch (_context15.prev = _context15.next) {
          case 0:
            return _context15.abrupt("return", request("".concat(CPAAS_PLATFORM).concat(rangePrefix, "/").concat(params.rangeId, "/rules"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context15.stop();
        }
      }
    }, _callee15);
  }));
  return _fetchRuleListToRange.apply(this, arguments);
}

export function deletePointToRange(_x16) {
  return _deletePointToRange.apply(this, arguments);
}
/**
 * 删除规则
 *  deletePointToRange
 * @param {Object} params - 查询参数
 */

function _deletePointToRange() {
  _deletePointToRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(params) {
    return _regeneratorRuntime.wrap(function _callee16$(_context16) {
      while (1) {
        switch (_context16.prev = _context16.next) {
          case 0:
            return _context16.abrupt("return", request("".concat(CPAAS_PLATFORM).concat(rangePrefix, "/").concat(params.rangeId, "/points"), {
              method: 'DELETE',
              body: params.list
            }));

          case 1:
          case "end":
            return _context16.stop();
        }
      }
    }, _callee16);
  }));
  return _deletePointToRange.apply(this, arguments);
}

export function deleteRuleToRange(_x17) {
  return _deleteRuleToRange.apply(this, arguments);
}
/**
 * 应用
 *  applyRules
 * @param {Object} params - 查询参数
 */

function _deleteRuleToRange() {
  _deleteRuleToRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(params) {
    return _regeneratorRuntime.wrap(function _callee17$(_context17) {
      while (1) {
        switch (_context17.prev = _context17.next) {
          case 0:
            return _context17.abrupt("return", request("".concat(CPAAS_PLATFORM).concat(rangePrefix, "/").concat(params.rangeId, "/rules"), {
              method: 'DELETE',
              body: params.list
            }));

          case 1:
          case "end":
            return _context17.stop();
        }
      }
    }, _callee17);
  }));
  return _deleteRuleToRange.apply(this, arguments);
}

export function applyRules(_x18) {
  return _applyRules.apply(this, arguments);
}

function _applyRules() {
  _applyRules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(params) {
    return _regeneratorRuntime.wrap(function _callee18$(_context18) {
      while (1) {
        switch (_context18.prev = _context18.next) {
          case 0:
            return _context18.abrupt("return", request("".concat(CPAAS_PLATFORM).concat(rangePrefix, "/").concat(params.rangeId, "/apply-rules"), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context18.stop();
        }
      }
    }, _callee18);
  }));
  return _applyRules.apply(this, arguments);
}